<template>
    <div>
        <el-card class="!border-none" shadow="never">
            <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
                <el-form-item label="用户ID">
                    <el-input
                            class="w-[150px]"
                            v-model="queryParams.uuid"
                            placeholder="请输入用户ID"
                            clearable
                            @keyup.enter="resetPage"
                    />
                </el-form-item>
                <el-form-item label="用户昵称/姓名/手机号">
                    <el-input
                            class="w-[280px]"
                            v-model="queryParams.user_keys"
                            placeholder="请输入用户昵称/姓名/手机号"
                            clearable
                            @keyup.enter="resetPage"
                    />
                </el-form-item>
                <el-form-item label="备注">
                    <el-input
                            class="w-[280px]"
                            v-model="queryParams.content"
                            placeholder="请输入备注"
                            clearable
                            @keyup.enter="resetPage"
                    />
                </el-form-item>
                <el-form-item label="来源">
                    <el-select class="w-[200px]" v-model="queryParams.from" clearable>
                        <template v-for="item in coupon_state">
                            <el-option :value="item.id" :label="item.name">{{item.name}}</el-option>
                        </template>
                    </el-select>
                </el-form-item>
                <el-form-item label="领取时间">
                    <daterange-picker
                        value-format="YYYY-MM-DD"
                        v-model:startTime="queryParams.start_time"
                        v-model:endTime="queryParams.end_time"
                    />
                </el-form-item>
                <el-form-item>
                    <el-button type="primary" @click="newResetPage">查询</el-button>
                    <el-button @click="resetParams">重置</el-button>
                </el-form-item>
            </el-form>
        </el-card>
        <el-card class="!border-none mt-4" shadow="never">
            <el-tabs class="demo-tabs" v-model="type" @tab-click="handleTabclick">
                <el-table size="large" v-loading="pager.loading" :data="pager.lists" style="width: 100%">
                    <el-table-column label="用户ID / 手机号 / 昵称" prop="name" min-width="180">
                        <template #default="{ row }">
                            {{ row.user.id }} / {{ row.user.phone }} / {{ row.user.nickname }}
                        </template>
                    </el-table-column>
<!--                    <el-table-column label="商品名称" prop="name"  min-width="150">-->
<!--                         <template #default="{ row }">-->
<!--                            {{ row.full_price }}-->
<!--                        </template>-->
<!--                    </el-table-column>-->
                    <el-table-column label="备注" prop="content"  min-width="150">
                         <template #default="{ row }">
                            {{ row.content }}
                        </template>
                    </el-table-column>
                    <el-table-column label="来源" prop="form"  min-width="150">
                        <template #default="{ row }">
                            <el-tag class="ml-2" :type="['info', 'success'][row.from-1]"> {{ coupon_state.map(res => res.name)[row.from-1] }}</el-tag>
                        </template>
                    </el-table-column>
                    <el-table-column label="领取时间" prop="name"  min-width="150">
                         <template #default="{ row }">
                            {{ row.created_at }}
                        </template>
                    </el-table-column>
<!--                    <el-table-column label="操作面板" min-width="160" fixed="right">-->
<!--                        <template #default="{ row }">-->
<!--                            <el-button type="danger" link @click="userDelete(row.id)">-->
<!--                                删除-->
<!--                            </el-button>-->
<!--                        </template>-->
<!---->
<!--                    </el-table-column>-->
                </el-table>
                <div class="flex justify-end mt-4">
                    <pagination v-model="pager" @change="getLists" />
                </div>
            </el-tabs>
        </el-card>
    </div>
</template>
<script lang="ts" setup>
    import { balanceList } from '@/api/eggManage'
    import { usePaging } from '@/hooks/usePaging'
    import feedback from "@/utils/feedback";
    import router, { getRoutePath } from '@/router'

    const coupon_state = [
        {
            id: 1,
            name: '系统发放'
        },
        {
            id: 2,
            name: '团长赠送'
        },
    ];

    const queryParams = reactive({
        uuid: '',
        user_keys: '',
        content: '',
        name: '',
        from: '',
        created_at: '',
        start_time: '',
        end_time: '',
    });

    const { pager, getLists, resetPage, resetParams } = usePaging({
        fetchFun: balanceList,
        params: queryParams
    });

    getLists();

    // 删除优惠卷
    const userDelete = async (id: number) => {
        // await feedback.confirm('确定删除该优惠卷？');
        // delUserCoupon({uuid: id});
        // getLists()
    };

    // 查询
    const newResetPage = async () => {
        queryParams.created_at = `${queryParams.start_time} - ${queryParams.end_time}`
        resetPage()
    };
</script>
